import _regeneratorRuntime from "@babel/runtime/regenerator";
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";

/**
 * uiPageService.js
 * @date 2018/9/29

 */
import request from 'utils/request';
import { CPAAS_PLATFORM } from 'utils/config';
import { parseParameter } from 'utils/utils';
export function uiPageSiteQueryPaging(_x) {
  return _uiPageSiteQueryPaging.apply(this, arguments);
}

function _uiPageSiteQueryPaging() {
  _uiPageSiteQueryPaging = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(params) {
    var query;
    return _regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            query = parseParameter(params);
            return _context.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/ui-pages"), {
              query: query,
              method: 'GET'
            }));

          case 2:
          case "end":
            return _context.stop();
        }
      }
    }, _callee);
  }));
  return _uiPageSiteQueryPaging.apply(this, arguments);
}

export function uiPageSiteCreate(_x2) {
  return _uiPageSiteCreate.apply(this, arguments);
}

function _uiPageSiteCreate() {
  _uiPageSiteCreate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(uiPage) {
    return _regeneratorRuntime.wrap(function _callee2$(_context2) {
      while (1) {
        switch (_context2.prev = _context2.next) {
          case 0:
            return _context2.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/ui-pages"), {
              body: uiPage,
              method: 'POST'
            }));

          case 1:
          case "end":
            return _context2.stop();
        }
      }
    }, _callee2);
  }));
  return _uiPageSiteCreate.apply(this, arguments);
}

export function uiPageSiteUpdate(_x3) {
  return _uiPageSiteUpdate.apply(this, arguments);
}

function _uiPageSiteUpdate() {
  _uiPageSiteUpdate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(uiPage) {
    return _regeneratorRuntime.wrap(function _callee3$(_context3) {
      while (1) {
        switch (_context3.prev = _context3.next) {
          case 0:
            return _context3.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/ui-pages"), {
              body: uiPage,
              method: 'PUT'
            }));

          case 1:
          case "end":
            return _context3.stop();
        }
      }
    }, _callee3);
  }));
  return _uiPageSiteUpdate.apply(this, arguments);
}

export function uiPageSiteQueryDetail(_x4) {
  return _uiPageSiteQueryDetail.apply(this, arguments);
}
/**
 * save page config
 * @param config
 * @returns {Promise<void>}
 */

function _uiPageSiteQueryDetail() {
  _uiPageSiteQueryDetail = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(pageCode) {
    return _regeneratorRuntime.wrap(function _callee4$(_context4) {
      while (1) {
        switch (_context4.prev = _context4.next) {
          case 0:
            return _context4.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/ui-pages/").concat(pageCode), {
              method: 'GET'
            }));

          case 1:
          case "end":
            return _context4.stop();
        }
      }
    }, _callee4);
  }));
  return _uiPageSiteQueryDetail.apply(this, arguments);
}

export function uiPageSiteDetailUpdate(_x5) {
  return _uiPageSiteDetailUpdate.apply(this, arguments);
}
/**
 * 查询 个性化应用
 * @param {number} organizationId
 * @param {string} pageCode
 * @returns {Promise<void>}
 */

function _uiPageSiteDetailUpdate() {
  _uiPageSiteDetailUpdate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(config) {
    return _regeneratorRuntime.wrap(function _callee5$(_context5) {
      while (1) {
        switch (_context5.prev = _context5.next) {
          case 0:
            return _context5.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/ui-pages/detail"), {
              method: 'PUT',
              body: config
            }));

          case 1:
          case "end":
            return _context5.stop();
        }
      }
    }, _callee5);
  }));
  return _uiPageSiteDetailUpdate.apply(this, arguments);
}

export function queryConfigsByPageCode(_x6, _x7) {
  return _queryConfigsByPageCode.apply(this, arguments);
}

function _queryConfigsByPageCode() {
  _queryConfigsByPageCode = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(organizationId, pageCode) {
    return _regeneratorRuntime.wrap(function _callee6$(_context6) {
      while (1) {
        switch (_context6.prev = _context6.next) {
          case 0:
            return _context6.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(organizationId, "/ui-pages/common/").concat(pageCode), {
              method: 'GET'
            }));

          case 1:
          case "end":
            return _context6.stop();
        }
      }
    }, _callee6);
  }));
  return _queryConfigsByPageCode.apply(this, arguments);
}

export function queryTplAndScriptsByPageCode(_x8, _x9) {
  return _queryTplAndScriptsByPageCode.apply(this, arguments);
}

function _queryTplAndScriptsByPageCode() {
  _queryTplAndScriptsByPageCode = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(organizationId, pageCode) {
    return _regeneratorRuntime.wrap(function _callee7$(_context7) {
      while (1) {
        switch (_context7.prev = _context7.next) {
          case 0:
            return _context7.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(organizationId, "/ui-pages/").concat(pageCode, "/tpl-and-scripts"), {
              method: 'GET'
            }));

          case 1:
          case "end":
            return _context7.stop();
        }
      }
    }, _callee7);
  }));
  return _queryTplAndScriptsByPageCode.apply(this, arguments);
}